//
//  webApi.swift
//  worldexchange
//
//  Created by xionghao on 2019/1/9.
//  Copyright © 2019 xionghao. All rights reserved.
//

import Foundation
import Moya
import CFNetwork
import RxSwift
import Alamofire

extension TargetType {
    public var baseURL: URL {
        
        return URL(string: HOST_URL)!
    }
}


enum WE {
    
    case login(username: String, password: String)
    
    case register(username: String, password: String, name:String, phone:String,email:String,code:String)
    
    case money()
    
    case rate(contact_id:Int,benchmark_id:Int)
    
    case question()
    
    case tance()
    
    case about()
    
    case shop()
    
    case email(email:String,phone:String)

    case banner()

    case call()
    
    case submit(token:String,title:String,ex_title:String,type:Int,money:String,ones:Int,city:Int,date:String)
    
    case orders(token:String)
    
    case message(token:String)
    
    case setting()
    
    case notice()
    

}

extension WE: TargetType {
    var path: String {
        switch self {
        case .login(_, _):
            return "/home/appAjax/login"
        case .register:
            return "/home/appAjax/register"
        case .money:
            return "/home/appAjax/money"
        case .rate:
            return "/home/appAjax/rate"
        case .question:
            return "/home/appAjax/problem"
        case .tance:
            return "/home/appAjax/tance"
        case .about:
            return "/home/appAjax/about"
        case .shop:
            return "/home/appAjax/contact"
        case .email:
            return "/home/appAjax/email"
        case .banner:
            return  "/home/appAjax/banner"
        case .call:
            return  "/home/appAjax/call"
        case .submit:
            return  "/home/appAjax/yuyue"
        case .orders:
            return  "/home/appAjax/appointments"
        case .message:
            return  "/home/appAjax/messages"
        case .setting:
            return "/home/appAjax/setting"
        case .notice:
            return "/home/appAjax/notices"
        default:
            return ""
        }
    }
    var headers: [String: String]? {
        return nil
    }
    
    var method: Moya.Method {
        switch self {
        case .login(_, _):
            return .post
        case .register:
            return .post
        case .money:
            return .get
        case .rate(_,_):
            return .get
        case .question:
            return .get
        case .tance:
            return .get
        case .about:
            return .get
        case .shop:
            return .get
        case .email:
            return .post
        case .call:
            return .get
        case .banner:
            return .get
        case .submit:
            return .post
        case .orders:
            return .get
        case .message:
            return .get
        case .setting:
            return .get
        case .notice:
            return .get
        default:
            return .get
        }
    }
    var task: Task {
        
        switch self {
        case .login(let username , let password):
            let params:[String:Any] = ["name":username,"password":password]
            return .requestParameters(parameters:params, encoding: URLEncoding.default)
        case .register(let username, let password,let name,let phone, let email, let code):
            let params:[String:Any] = ["title":username,"ex_title":password,"code":code,"email":email,"name":name,"phone":phone,"repassword":password]
            
            return .requestParameters(parameters:params, encoding: URLEncoding.default)
        case .money :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .rate(let contact_id , let benchmark_id) :
            let params:[String:Any] = ["contact_id":contact_id,"benchmark_id":benchmark_id]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .question :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .tance :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .about :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .shop :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .email(let email,let phone) :
            let params:[String:Any] = ["email":email,"phone":phone]
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case .banner() :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case .call() :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case .submit(let token,let title,let ex_title, let type, let money ,let ones, let city, let date) :
            let params:[String:Any] = ["token":token,"title":title,"ex_title":ex_title,"type":type,"money":money,"ones":ones,"city":city,"date":date]
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
            
        case .orders(let token) :
            let params:[String:Any] = ["token":token]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .message(let token) :
            let params:[String:Any] = ["token":token]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .setting() :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        case .notice() :
            let params:[String:Any] = [:]
            return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
        }
        
        
    }
    
    var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    
    
}
